package home.game.client.display.models;

import home.game.client.controllers.Controllable;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Observable;

/**
 */
public class Tile extends Observable implements Controllable {
    private JPanel tile;
    private BufferedImage tileObject;
    private PlayerType owner;


    public void initTile() {
        tile = new TilePanel();
        tile.setBackground(Color.WHITE);
        tile.setBorder(BorderFactory.createBevelBorder(1));
    }

    public JPanel getPanel() {
        return tile;
    }

    public void setTileObject(BufferedImage tileObject) {
        this.tileObject = tileObject;
        setChanged();
        notifyObservers();
    }

    public BufferedImage getTileObject() {
        return tileObject;
    }

    public void setOwner(PlayerType owner) {
        this.owner = owner;
    }

    public PlayerType getOwner() {
        return owner;
    }

    private class TilePanel extends JPanel {
        @Override
        protected void paintComponent(Graphics g) {
            if (tileObject != null) {
                g.drawImage(tileObject, 0, 0, this.getWidth(), this.getHeight(), null);
            }
        }
    }
}
